<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item
              label="供应能力名称"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              prop="offerAbilityName"
            >
              <a-input v-model="model.offerAbilityName" placeholder="请输入供应能力名称"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item
              label="供应能力说明"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              prop="offerAbilityInstruction"
            >
              <a-textarea v-model="model.offerAbilityInstruction" rows="4" placeholder="请输入供应能力说明" />
            </a-form-model-item>
          </a-col>

          <a-col :span="24">
            <a-form-model-item label="供应报价(元)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="offerPrice">
              <a-input-number v-model="model.offerPrice" placeholder="请输入供应报价" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="能力证书(png、pdf)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="certificate">
              <j-image-upload isMultiple v-model="model.certificate"></j-image-upload>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item
              label="其他资质(png、pdf)"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              prop="otherCertificates"
            >
              <j-image-upload isMultiple v-model="model.otherCertificates"></j-image-upload>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="联系人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="contactPerson">
              <a-input v-model="model.contactPerson" placeholder="请输入联系人"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item
              label="联系人电话"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              prop="contactPhoneNumber"
            >
              <a-input v-model="model.contactPhoneNumber" placeholder="请输入联系人电话"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="remark">
              <a-textarea v-model="model.remark" rows="4" placeholder="请输入备注" />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>
import { httpAction, getAction } from '@/api/manage'
import { validateDuplicateValue } from '@/utils/util'

export default {
  name: 'HTAbilityDemandOfferForm',
  components: {},
  props: {
    //表单禁用
    disabled: {
      type: Boolean,
      default: false,
      required: false
    }
  },
  data() {
    return {
      model: {},
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      },
      confirmLoading: false,
      validatorRules: {
        offerAbilityName: [{ required: true, message: '请输入供应能力名称!' }],
        offerAbilityInstruction: [{ required: true, message: '请输入供应能力说明!' }],
        certificate: [{ required: true, message: '请上传能力证书!' }],
        contactPerson: [{ required: true, message: '请输入联系人!' }],
        contactPhoneNumber: [{ required: true, message: '请输入联系人电话!' }]
      },
      url: {
        add: '/ability/hTAbilityDemandOffer/add',
        edit: '/ability/hTAbilityDemandOffer/edit',
        queryById: '/ability/hTAbilityDemandOffer/queryById'
      }
    }
  },
  computed: {
    formDisabled() {
      return this.disabled
    }
  },
  created() {
    //备份model原始值
    this.modelDefault = JSON.parse(JSON.stringify(this.model))
  },
  methods: {
    add() {
      this.edit(this.modelDefault)
    },
    edit(record) {
      this.model = Object.assign({}, record)
      this.visible = true
    },
    submitForm() {
      const that = this
      return new Promise((resolve, reject) => {
        that.$refs.form.validate(valid => {
          if (valid) {
            that.$emit('ok')
            resolve(that.model)
          }
        })
      })
    }
  }
}
</script>
